package com.hackathon.sgstern.adapter;

import com.hackathon.sgstern.R;
import com.hackathon.sgstern.dataprovider.LogoProvider;
import com.hackathon.sgstern.model.Sports;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SpinnerSportsAdapter extends BaseAdapter {

	Sports[] sportTypes;
	LayoutInflater inflator;
	Context context;

	public SpinnerSportsAdapter(Context context) {
		inflator = LayoutInflater.from(context);
		this.context = context;
		sportTypes = Sports.values();
	}

	@Override
	public int getCount() {
		return sportTypes.length;
	}

	@Override
	public Object getItem(int position) {
		return sportTypes[position];
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Sports sport = sportTypes[position];
		convertView = inflator.inflate(R.layout.spinner_item_sports, null);
		TextView tv = (TextView) convertView
				.findViewById(R.id.spinner_sports_text);
		ImageView image = (ImageView) convertView
				.findViewById(R.id.spinner_sports_icon);
		Bitmap bitmap = LogoProvider.retrieveBitmap(context, sport);
		image.setImageBitmap(bitmap);
		tv.setText(sport.toString());
		return convertView;
	}
}
